# -- coding: utf-8 --
#上面这个解决的是中文注释报错问题

# 构造方法:python没有重载机制，所以构造方法只能有一个
class Foobar1(object):
    def __init__(self):
        self.somevar='abc'

class Foobar2(object):
    def __init__(self,value=12):
        self.somevar=value

class Father(object):
    def __init__(self):
        self.name='abc'
    def printMsg(self):
        print self.name
        # 如果没有age属性，就会异常，这里进行了异常捕获
        try:
            print self.age
        except AttributeError:
            pass

class Child(Father):
    def __init__(self):
        super(Child, self).__init__()
        # Father.__init__(self)等价于super(Child, self).__init__()
        self.age='123'

if __name__ == '__main__':
    foobar1=Foobar1()
    print foobar1.somevar

    foobar2=Foobar2("123")
    print foobar2.somevar

    c1=Child()
    c1.printMsg()
    f1=Father()
    f1.printMsg()